module.exports = function ($scope, $resource, $modalInstance, bean, toaster, FileUploader) {
    $scope.bean;
    $scope.url = '/api/as/mc/shopclass/save'
    if (bean) {
        $scope.bean = bean;
        $scope.url = '/api/as/mc/shopclass/update'
    } else {
        $scope.bean = {
            class_name: '',
            class_code: '',
            class_state: '1',
            asrot: 1,
            logo: '',
            style_id: ''
        };
    }
    $resource('/api/as/mc/style/list', {}, {}).save($scope.bean, function (res) {
        if (res.errcode === 0) {
            $scope.styleList = res.data;
            if ($scope.styleList.length > 0 && !bean) {
                $scope.bean.style_id = $scope.styleList[0].id;
            }
        } else {
            toaster.error({ title: '', body: res.errmsg });
        }
    });

    //保存
    $scope.ok = function () {
        $resource($scope.url, {}, {}).save($scope.bean, function (res) {
            if (res.errcode === 0) {
                toaster.success({ title: '', body: '操作成功' });
                $modalInstance.close();
            } else {
                toaster.error({ title: '', body: res.errmsg });
            }
        });
    }

    //取消
    $scope.close = function () {
        $modalInstance.dismiss('cancel');
    }

    $scope.uploader = new FileUploader({
        url: 'https://txy.juyouhx.com/Api/Api/ObjectToOss?topdir=skv4&selfdir=orderinfo'+ Date.parse(new Date())
    });

    $scope.uploader.filters.push({
        name: 'imageFilter',
        fn: function (item /*{File|FileLikeObject}*/, options) {
            var type = '|' + item.type.slice(item.type.lastIndexOf('/') + 1) + '|';
            return '|jpg|png|jpeg|bmp|gif|'.indexOf(type) !== -1;
        }
    });

    $scope.uploader.onSuccessItem = function (fileItem, response, status, headers) {
        $scope.bean.logo = response.savename;
    };
};